package com.chenwei.rabbit.routingTopics;


import com.chenwei.rabbit.MQUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;

/**fanout模型（广播）
 * 每个 消费者绑定一个队列
 * 生产者和队列绑定交换机
 * @author: chenwei
 * @date: 2021/4/1 9:47
 */
public class Provider {
    public static void main(String[] args) throws IOException {
        Connection connection = MQUtils.getConnection();
        Channel channel = connection.createChannel();
        //将通道声明指定得交换机 参数1:交换机名称 参数2：交换机类型
        channel.exchangeDeclare("routingTopic", "topic");
        //路由key
        String routingKey="aa.bb.cc";//动态路由key
        //发布三条消息
        for (int i = 0; i < 3; i++) {
            //发送消息 参数2 路由key
            channel.basicPublish("routingTopic",routingKey,null,("routingTopic msg为"+routingKey+i).getBytes());
        }
        //释放资源
        MQUtils.close(channel,connection);


    }
}
